package com.example.demo.servlet;

import com.example.demo.dao.NewsDao;
import com.example.demo.dao.NoticeDao;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/newsDel.jsp")
public class NewsDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int NewID = Integer.parseInt(req.getParameter("NewID"));
        int result = (new NewsDao()).delete(NewID);
        if (result > 0) {
            resp.sendRedirect("news.jsp");
        }else {
            req.setAttribute("msg","删除失败");
            req.setAttribute("url","news.jsp");
            req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
        }
    }
}
